package com.renting.common.utils;


import org.springframework.util.StringUtils;

import java.util.UUID;

public class SweetStringUtils {


    /**
     * 驼峰命名改为下划线命名
     *
     * @param name
     * @return
     */
    public static String transLateUpper2UnderLine(final String name) {
        String rtn = name;
        if (!StringUtils.isEmpty(name)) {
            rtn = name.replaceAll("([A-Z])", "_$1").toUpperCase().replaceAll("^_+", "");
        }
        return rtn;
    }

    /**
     * 下划线转驼峰
     *
     * @param name
     * @return
     */
    public static String transLateUnderLine2Upper(final String name) {
        String rtn = "";
        if (!StringUtils.isEmpty(name)) {
            String[] splits = name.toLowerCase().split("_");
            for (String str : splits) {
                rtn += (str.substring(0, 1).toUpperCase() + str.substring(1));
            }
            rtn = rtn.substring(0, 1).toLowerCase() + rtn.substring(1);
        }
        return rtn;
    }

    public static String getUUIDNoBreak() {
        return String.valueOf(UUID.randomUUID()).replaceAll("-", "");

    }
}
